package algorithms;

import wheel.M209Wheels;
import bar.Lug;
import bar.M209Bars;

public class StringToSetting {

    public static void stringToSetting(M209Bars m209bars, M209Wheels m209wheels, String sSetting) {
	String[] rows = sSetting.split("\n", 33);
	if (rows.length == 33) {
	    for (int i = 0; i < 27; i++) {
		String[] lugs = (rows[i].split(":", 2)[1]).split(",", 2);
		// System.out.println(lugs[0]+'-'+lugs[1]);
		m209bars.getBars().get(i).setLugs(Lug.StringToLug(lugs[0]), Lug.StringToLug(lugs[1]));
	    }
	    for (int i = 27; i < 33; i++) {
		// System.out.println(rows[i]);
		for (int j = 0; j < rows[i].length(); j++) {
		    if (rows[i].charAt(j) != '\n' && rows[i].charAt(j) != '-') {
			Key key = Key.charToKey(rows[i].charAt(j));
			if (m209wheels.getKeyWheels().get(i - 27).getKeyPins().containsKey(key)) {
			    m209wheels.getKeyWheels().get(i - 27).getKeyPins().put(key, true);
			}
		    }
		}
	    }
	}
    }
}
